package com.sheyu.mall.cart.exception;

import com.sheyu.common.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author sheyu
 * @Desciption:
 * @date 2020/9/1 4:51 下午
 */

@ControllerAdvice
public class RuntimeExceptionHandler {

    /**
     * 异常处理流程
     * @param exception
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public R handler(RuntimeException exception){
        return R.error(exception.getMessage());
    }

    @ExceptionHandler(CartExceptionHandler.class)
    public R userHandler(CartExceptionHandler cartExceptionHandler){
        return R.error("购物车无此商品");
    }
}
